package top.riske.gen3d.common.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.riske.gen3d.http.exception.BisException;
import top.riske.gen3d.http.response.Result;

import java.time.LocalDateTime;

@Tag(name = "MainController", description = "根路径控制器")
@RestController
@RequestMapping("/api")
public class MainController {

    @Operation(summary = "测试系统是否联通")
    @GetMapping("/")
    public Result<String> index() {
        return Result.success(LocalDateTime.now().toString());
    }

    @Operation(summary = "测试空返回值")
    @GetMapping("/void")
    public void returnVoid(){
    }

    @Operation(summary = "测试返回异常")
    @GetMapping("/exception")
    public void businessException(){
        throw new BisException("异常");
    }

    @Operation(summary = "测试未捕获的全局异常")
    @GetMapping("/exception/global")
    public void globalBusinessException(){
        int a = 1/0;
    }

    /**
     * 测试受保护接口
     */
    @RequestMapping("/protected/admin")
    public Result<String> admin(HttpServletRequest request){
        return Result.success("admin");
    }

    /**
     * 测试受保护接口
     */
    @RequestMapping("/protected/user")
    public Result<String> user(HttpServletRequest request){
        return Result.success("user");
    }

}
